<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:s="http://jboss.com/products/seam/taglib"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:fb="http://www.facebook.com/2008/fbml"
                xmlns:a="http://richfaces.org/a4j"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:c="http://java.sun.com/jstl/core"
                template="/template/kiwi/template_1col.xhtml">

    <ui:define name="stylesheet">
        <link rel="stylesheet" type="text/css" href="stylesheet/kiwi/elements/search.css" />
    </ui:define>

    <ui:define name="center">
        <div class="box">
            <p:messages id="msgs" showDetail="false" />
            <h2 style="position:absolute">KWQL</h2>
            <div id="article" style="float:none;width: 100%;">
                <div id="search_single_center">
                    <h:form prependId="false">
                        <div id="searchbar" style="padding-top:20px;">
                            <h:inputText value="#{kwqlAction.searchEngine.KWQLQuery}" size="65" id="searchField"/>
                            <!--
	                    <rich:suggestionbox for="searchField" suggestionAction="#{kwqlaAction.searchEngine.autocomplete}" var="result">
		                    <h:column>
		                        <h:outputText value="#{result}" />
		                    </h:column>
	                    </rich:suggestionbox>
	                    -->
                            <a:commandButton
                                action="#{kwqlAction.searchEngine.runSearch()}"
                                style="margin-left:10px;margin-right:10px;"
                                value="#{messages['hdr.search']}"
                                reRender="#{kwqlAction.renderedSearchPageParts()}">
                                <s:defaultAction />
                            </a:commandButton>
                            <a href="kwql.xhtml#" style="font-size:11px;" onclick="if(jQuery('#extSearch').is(':hidden')){jQuery('#extSearch').slideDown('slow');}else{jQuery('#extSearch').slideUp('slow');}">
                                <h:outputText value="Extended Search" />
                            </a>
                            <span style="margin-left:5px"/>
                            <s:link view="/KQB/home"
                                    style="font-size:11px;"
                                    value="visKWQL">
                                <f:param name="q" value="#{searchAction.searchEngine.searchQuery}"/>
                            </s:link>
                            <!-- extended search -->
                            <div id="extSearch" style="display: none;margin-top:10px;">
                                <table style="width:100%;border:none;">
                                    <tr>
                                        <td width="165px;" style="color:#8BC53E;padding:2px;">
                                            <h:outputText value="Search Engines:" />
                                        </td>
                                        <td>
                                            <s:link view="/search.xhtml" value="KiWi">
                                                <f:param name="q" value="#{searchAction.searchEngine.searchQuery}" />
                                            </s:link>
                                            <h:outputText value=" - " style="margin-left:5px;margin-right:5px;"/>
                                            <s:link view="/exhibit.xhtml" value="Exhibit">
                                                <f:param name="q" value="#{searchAction.searchEngine.searchQuery}" />
                                            </s:link>
                                            <h:outputText value="-" style="margin-left:5px;margin-right:5px;"/>
                                            <s:link view="/kwql.xhtml" value="KWQL">
                                                <f:param name="q" value="#{searchAction.searchEngine.searchQuery}" />
                                            </s:link>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="color:#8BC53E;padding:2px;">
                                            <h:outputText value="Last Searches:" />
                                        </td>
                                        <td>
                                            <c:forEach items="#{kiwi.dashboard.userHistoryAction.lastSearches}" var="search" varStatus="status">
                                                <h:outputText value="-" style="margin-left:5px;margin-right:5px;" rendered="#{status.index != 0}" />
                                                <s:link view="/kwql.xhtml" value="#{search.searchString}">
                                                    <f:param name="q" value="#{search.searchString}" />
                                                </s:link>
                                            </c:forEach>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="color:#8BC53E;padding:2px;">
                                            <h:outputText value="Personalized Search:" />
                                        </td>
                                        <td>
                                            <h:selectBooleanCheckbox title="Sign in, tag and search" value="#{searchAction.searchEngine.personalSearch}" id="checkboxID">
                                                <a:support id="checkboxSupport" event="onchange" reRender="#{searchAction.renderedSearchPageParts()}" />
                                            </h:selectBooleanCheckbox>
                                        </td>
                                    </tr>
                                </table>

                            </div>
                        </div>

                        <div id="search_size">

                            <s:fragment rendered="#{kwqlAction.searchEngine.searchResults.resultCount > 0}">

                                <!-- number of results -->
                                <s:span id="nrOfResults">
                                    <h:outputText value="Results #{(kwqlAction.searchEngine.page-1) * kwqlAction.searchEngine.pageSize + 1} - #{kwqlAction.searchEngine.min(kwqlAction.searchEngine.searchResults.resultCount, (kwqlAction.searchEngine.page * kwqlAction.searchEngine.pageSize))} of totally #{kwqlAction.searchEngine.searchResults.resultCount} ordered by" />
                                    <h:outputText value=" " />
                                </s:span>

                                <!-- searchfield -->
                                <rich:inplaceSelect id="searchorderby" value="#{kwqlAction.searchEngine.orderBy}" defaultLabel="Click here to edit">
                                    <a:support event="onviewactivated" action="#{kwqlAction.searchEngine.getResults(true)}" reRender="searchorderby,searchresults" />
                                    <s:selectItems value="#{kwqlAction.searchEngine.orderBys}" var="orderBy" label="#{orderBy}" />
                                </rich:inplaceSelect>

                                <h:outputText value=" " />

                                <!-- order -->
                                <rich:inplaceSelect id="searchorder" value="#{kwqlAction.searchEngine.order}" defaultLabel="Click here to edit">
                                    <a:support event="onviewactivated" action="#{kwqlAction.searchEngine.getResults(true)}" reRender="searchorder,searchresults" />
                                    <s:selectItems value="#{kwqlAction.searchEngine.orders}" var="order" label="#{kiwi.messages.getProperty(order)}" />
                                </rich:inplaceSelect>

                            </s:fragment>

                            <s:fragment rendered="#{kwqlAction.searchEngine.searchResults.resultCount == 0}">
                                <h:outputText value="no Results" />
                            </s:fragment>

                        </div>

                        <!--  the search results in the left column -->
                        <s:div id="searchresults" style="clear:left;">
                            <c:forEach items="#{kwqlAction.searchEngine.currentResults.results}" var="r" >
                                <hr style="clear:both;"/>
                                <!-- include template to show one result item. -->
                                <ui:include src="kwql.xhtml#{kiwi.wiki.ui.layoutAction.getSearchResultItemTemplate(r.item)}">
                                    <ui:param name="ci" value="#{r.item}" />
                                    <ui:param name="mode" value="#{kiwi.wiki.ui.layoutAction.viewMode}" />
                                    <ui:param name="score" value="#{r.score}" />
                                    <ui:param name="ceq" value="#{r.ceq}" />
                                    <ui:param name="preview" value="#{kwqlAction.searchEngine.getPreview(r.item)}"/>
                                </ui:include>
                                <br/>
                            </c:forEach>
                        </s:div>

                        <s:div id="resultNavigation">
                            <s:fragment rendered="#{kwqlAction.searchEngine.pages.size > 1}">
                                <!-- result navigation -->
                                <span class="back">
                                    <a:commandLink action="#{kwqlAction.searchEngine.prevPage()}" value="back" reRender="#{kwqlAction.renderedSearchPageParts()}" disabled="#{kwqlAction.searchEngine.page eq 1}" />
                                </span>

                                <c:forEach items="#{kwqlAction.searchEngine.pages}" var="page">
                                    <s:span rendered="#{ page eq 1 and kwqlAction.searchEngine.page > 5 }">
                                        <a:commandLink action="#{kwqlAction.searchEngine.setPage(page)}"
                                                       value="#{page}"
                                                       reRender="#{kwqlAction.renderedSearchPageParts()}" />
                                        <h:outputText value=" ... " />
                                    </s:span>

                                    <s:span styleClass="selected" rendered="#{page eq kwqlAction.searchEngine.page}">
                                        <h:outputText value="#{page}" />
                                    </s:span>

                                    <s:span rendered="#{ (page eq kwqlAction.searchEngine.pages.size) and ((page-kwqlAction.searchEngine.page) > 5) }">
                                        <h:outputText value=" ... " />
                                        <a:commandLink
                                            action="#{kwqlAction.searchEngine.setPage(page)}"
                                            value="#{page}"
                                            reRender="#{kwqlAction.renderedSearchPageParts()}" />
                                    </s:span>

                                    <s:span rendered="#{(page != kwqlAction.searchEngine.page) and (5 > page - kwqlAction.searchEngine.page) and (page - kwqlAction.searchEngine.page > -5) }">
                                        <a:commandLink
                                            action="#{kwqlAction.searchEngine.setPage(page)}"
                                            value="#{page}"
                                            reRender="#{kwqlAction.renderedSearchPageParts()}" />
                                    </s:span>

                                    <h:outputText value=" " />
                                </c:forEach>
                                <span class="next">
                                    <a:commandLink action="#{kwqlAction.searchEngine.nextPage()}" value="next" reRender="#{kwqlAction.renderedSearchPageParts()}" disabled="#{kwqlAction.searchEngine.page eq kwqlAction.searchEngine.pages.size}" />
                                </span>
                            </s:fragment>
                        </s:div>
                        <!--
				<s:div id="resultNavigation">

				    <c:if test="${kwqlAction.searchEngine.pages.size>1}">
	               <table width="100%">
	                   <tr>
	                       <td width="20%">
	                           <a:commandButton action="#{kwqlAction.searchEngine.prevPage()}" 
	                           		value="previous page" 
	                           		reRender="#{kwqlAction.renderedSearchPageParts()}" 
	                           		disabled="#{kwqlAction.searchEngine.page eq 1}"/>
	                       </td>
	                       <td style="text-align: center; font-size: 140%;">
                       		   <c:forEach items="#{kwqlAction.searchEngine.pages}" var="page">
	                            	<s:span rendered="#{ page eq 1 and kwqlAction.searchEngine.page > 5 }">
	                            		<a:commandLink action="#{kwqlAction.searchEngine.setPage(page)}" 
	                            			value="#{page}" 
	                            			reRender="#{kwqlAction.renderedSearchPageParts()}" />
	                            		<h:outputText value=" ... " />	                            	
	                            	</s:span>

	                            	<s:span rendered="#{page eq kwqlAction.searchEngine.page}">
	                            		<strong>
			                            	<h:outputText value="#{page}"/>
			                            </strong>
	                            	</s:span>

	                            	<s:span rendered="#{ (page eq kwqlAction.searchEngine.pages.size) and ((page-kwqlAction.searchEngine.page) > 5) }">
	                            		<h:outputText value=" ... " />	                            	
	                            		<a:commandLink action="#{kwqlAction.searchEngine.setPage(page)}" 
	                            			value="#{page}" 
	                            			reRender="#{kwqlAction.renderedSearchPageParts()}" />
	                            	</s:span>

	                            	<s:span rendered="#{(page != kwqlAction.searchEngine.page) and (5 > page - kwqlAction.searchEngine.page) and (page - kwqlAction.searchEngine.page > -5) }">
	                            		<a:commandLink action="#{kwqlAction.searchEngine.setPage(page)}" 
	                            			value="#{page}" 
	                            			reRender="#{kwqlAction.renderedSearchPageParts()}" />
	                            	</s:span>

	                           		<h:outputText value=" " />
	                           </c:forEach>
	                       </td>
	                       <td style="text-align: right" width="20%">
	                           <a:commandButton action="#{kwqlAction.searchEngine.nextPage()}" 
	                           		value="next page" 
	                           		reRender="#{kwqlAction.renderedSearchPageParts()}" 
	                           		disabled="#{kwqlAction.searchEngine.page eq kwqlAction.searchEngine.pages.size}"/>
	                       </td>    
	                   </tr>
	               </table>
	               </c:if>
				</s:div>
				-->
                    </h:form>
                </div>
            </div>
        </div>

    </ui:define>
</ui:composition>

